package com.app.dialoglibrary.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.applibrary.R;
import com.app.dialoglibrary.bean.ShareInfo;
import com.app.customviewlibrary.recyclerviewlib.BaseInfo;
import com.app.customviewlibrary.recyclerviewlib.BaseRecycleAdapter;
import com.app.customviewlibrary.recyclerviewlib.BaseRecycleViewHolder;

import java.util.List;

public class DialogItemAdapter extends BaseRecycleAdapter {

    public DialogItemAdapter(Context context, List dataList) {
        super(context, dataList);
    }

    @NonNull
    @Override
    public BaseRecycleViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        return new ShareItemViewHolder(layoutInflater.inflate(
                R.layout.item_horizontal_layout,
                viewGroup, false));
    }

    @Override
    public void onBindViewHolder(BaseRecycleViewHolder baseRecycleViewHolder, int i) {
        super.onBindViewHolder(baseRecycleViewHolder, i);
    }

    @Override
    public int getItemViewType(int position) {
        BaseInfo baseInfo = (BaseInfo) dataList.get(position);
        return baseInfo.getViewType();
    }

    class ShareItemViewHolder extends BaseRecycleViewHolder{
        private ImageView itemIv;
        private TextView itemTv;
        private ShareItemViewHolder(View itemView) {
            super(itemView);
            itemIv = itemView.findViewById(R.id.item_iv);
            itemTv = itemView.findViewById(R.id.item_tv);

        }

        @Override
        public void setItemDataToShow(int position, Object object) {
            if(null != object){
                ShareInfo shareInfo = (ShareInfo) object ;
                itemIv.setImageResource(shareInfo.getShareRes());
                itemTv.setText(shareInfo.getShareHint());
            }
        }
    }
}
